package service

import "fmt"

const GlobalConfigServiceID = "global"

type IGlobalConfig interface {
	Check() error
}

type IConfig interface {
	ID() int
	SetID(id int)
	Check() error
}

type Config struct {
	id int
	//LogDir           string
	//UseConsoleLogger bool
	//PprofIP          string // pprof监听IP，禁止用公网IP
	//PprofPort        int    // pprof监听端口
	//EndpointIP       string // rpc监听IP
	//EndpointPort     int    // rpc监听端口
	PutPayloadSec int // 更新负载间隔(单位:秒)
}

func (c Config) ID() int {
	return c.id
}

func (c *Config) SetID(id int) {
	c.id = id
}

func (c *Config) Check() error {
	if c.id <= 0 {
		return fmt.Errorf("invalid Service.ID")
	}
	//if !c.UseConsoleLogger && c.LogDir == "" {
	//	return fmt.Errorf("invalid Service.LogDir")
	//}
	//if c.EndpointIP == "" {
	//	return fmt.Errorf("invalid Service.EndpointIP")
	//}
	if c.PutPayloadSec < 5 {
		return fmt.Errorf("invalid Service.PutPayloadSec, must >= 5")
	}
	return nil
}
